package com.yingxue.demo.service.impl;

import com.alibaba.fastjson.JSON;
import com.yingxue.demo.entity.User;
import com.yingxue.demo.mapper.UserMapper;
import com.yingxue.demo.service.HomeService;
import com.yingxue.demo.vo.resp.HomeRespVO;
import com.yingxue.demo.vo.resp.PermissionTreeNodeRespVO;
import com.yingxue.demo.vo.resp.UserInfoRespVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Package: com.yingxue.demo.service.impl
 * @Author: Mr.Waves
 * @Date: 2020-03-31 10:47
 * @Description:
 **/
@Service
public class HomeServiceImpl implements HomeService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public HomeRespVO getHomeDataByUserId(Long userId) {
        HomeRespVO homeRespVO = new HomeRespVO();
        UserInfoRespVO userInfoRespVO = new UserInfoRespVO();

        /*
         * mock 左侧导航栏数据
         */
        List<PermissionTreeNodeRespVO> leftNavigationBar = new ArrayList<>();
        PermissionTreeNodeRespVO treeNode1 = new PermissionTreeNodeRespVO();
        treeNode1.setTitle("菜单权限管理");
        treeNode1.setUrl("/index/permissionMenu");

        leftNavigationBar.add(treeNode1);
        homeRespVO.setLeftNavigationBar(leftNavigationBar);
        // 查询用户信息
        User user = userMapper.selectById(userId);
        if (null != user) {
            userInfoRespVO.setUsername(user.getUsername());
            userInfoRespVO.setDeptName("迎学教育");
            userInfoRespVO.setId(user.getId());
        }
        homeRespVO.setUserInfoRespVO(userInfoRespVO);

        return homeRespVO;
    }
}
